﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;

namespace EAppointmentsWPF
{
	public partial class Login
	{
		string username;
		public Login()
		{

			this.InitializeComponent();
           // Insert code required on object creation below this point.
		}

        #region Event Handler
        public event EventHandler EnablingItems;
        #endregion

        private void btnSignIn_Click(object sender, RoutedEventArgs e)
        {
            string str = txtPassword.Password.ToString();
            string str1 = str.ToLower();
            str = txtUsername.Text;
            username = str.ToLower();

            if (username.Equals("sanjiv") && str1.Equals("p@ssw0rd"))
            {
               // ((Storyboard)this.Resources["LoginScreenDisappear"]).Begin(this);
                this.Visibility = Visibility.Collapsed;
                if (EnablingItems != null)
                {
                    EnablingItems(sender, new EventArgs());
                }
                
            }
            else
            {
                MessageBox.Show("Invalid username or password", "Login Error", MessageBoxButton.OK, MessageBoxImage.Error);
                txtPassword.Clear();
                txtPassword.Focus();
            }
        }
        
      
        private void txtUsername_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                btnSignIn_Click(sender, new RoutedEventArgs());
            }
        }

        private void txtPassword_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                btnSignIn_Click(sender, new RoutedEventArgs());
            }
            
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            txtUsername.Focus();
        }
               
	}
}